package com.hzncc.scaffold.service.impl;

import com.hzncc.scaffold.core.ResultT;
import com.hzncc.scaffold.entity.Other.Question;
import com.hzncc.scaffold.mapper.QuestionMapper;
import com.hzncc.scaffold.service.QuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 问题表 服务实现类
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService {

    @Autowired
    QuestionService questionService;

    @Override
    public ResultT addQuestion(Question question) {
        boolean save = questionService.save(question);

        if (save) {
            return ResultT.success("新增成功");
        } else {
            return ResultT.fail("新增失败");
        }
    }

    @Override
    public ResultT updateQuestion(Question question) {
        boolean update = questionService.updateById(question);
        if (update) {
            return ResultT.success("修改成功");
        } else {
            return ResultT.fail("修改失败");
        }
    }

    @Override
    public ResultT deleteQuestion(List<Integer> questionId, String questionLibId) {

        for (Integer id : questionId) {
             boolean remove = questionService.removeById(id);
             if(!remove){
                 return ResultT.fail("删除失败");
             }
        }
        return ResultT.success("删除成功");
    }
}
